#include "stdafx.h"
#include "Fakes/FakeD3D10Device.h"
#include "Fakes/FakeD3D10Texture2D.h"

DESCRIPTION_10_TEST_SUITE_CTOR(Texture2DDescription, (DXGI_FORMAT_R8G8B8A8_UINT, 256, 128))

BOOST_FIXTURE_TEST_CASE(Default, TestTexture2DDescription)
{
	BOOST_REQUIRE_EQUAL(DXGI_FORMAT_R8G8B8A8_UINT, m_desc.Format);
	BOOST_REQUIRE_EQUAL(256, m_desc.Width);
	BOOST_REQUIRE_EQUAL(128, m_desc.Height);
	BOOST_REQUIRE_EQUAL(1, m_desc.ArraySize);
	BOOST_REQUIRE_EQUAL(0, m_desc.MipLevels);
	BOOST_REQUIRE_EQUAL(D3D10_BIND_SHADER_RESOURCE, m_desc.BindFlags);
	BOOST_REQUIRE_EQUAL(D3D10_USAGE_DEFAULT, m_desc.Usage);
	BOOST_REQUIRE_EQUAL(0, m_desc.CPUAccessFlags);
	BOOST_REQUIRE_EQUAL(1, m_desc.SampleDesc.Count);
	BOOST_REQUIRE_EQUAL(0, m_desc.SampleDesc.Quality);
	BOOST_REQUIRE_EQUAL(0, m_desc.MiscFlags);
}

#define TEXTURE2D_DESCRIPTION_TEST_CASE(type_, name_, value_) \
	DESCRIPTION_10_TEST_CASE(type_, name_, value_, Texture2DDescription)

TEXTURE2D_DESCRIPTION_TEST_CASE(UINT, ArraySize, 1)
TEXTURE2D_DESCRIPTION_TEST_CASE(UINT, MipLevels, 2)
TEXTURE2D_DESCRIPTION_TEST_CASE(UINT, BindFlags, D3D10_BIND_RENDER_TARGET)
TEXTURE2D_DESCRIPTION_TEST_CASE(D3D10_USAGE, Usage, D3D10_USAGE_DYNAMIC)
TEXTURE2D_DESCRIPTION_TEST_CASE(UINT, CPUAccessFlags, D3D10_CPU_ACCESS_READ)
DESCRIPTION_10_FIXTURE_TEST_CASE(SampleCount_, Texture2DDescription, UINT, 2, SampleDesc.Count)
DESCRIPTION_10_FIXTURE_TEST_CASE(SampleQuality_, Texture2DDescription, UINT, 2, SampleDesc.Quality)
TEXTURE2D_DESCRIPTION_TEST_CASE(UINT, MiscFlags, D3D10_RESOURCE_MISC_GDI_COMPATIBLE)

BOOST_FIXTURE_TEST_CASE(CreateNoData, TestTexture2DDescription)
{
	FakeD3D10Device device;
	FakeD3D10Texture2D texture;
	device.CreateTexture2DFakeResult = &texture;
	device.CreateTexture2DFakeHResult = S_OK;
	ID3D10Texture2D *result = m_desc.Create(&device);
	BOOST_REQUIRE(device.CreateTexture2DCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateTexture2DLastDesc);
	BOOST_REQUIRE_EQUAL(&texture, result);
}

BOOST_FIXTURE_TEST_CASE(CreateWithData, TestTexture2DDescription)
{
	FakeD3D10Device device;
	FakeD3D10Texture2D texture;
	device.CreateTexture2DFakeResult = &texture;
	device.CreateTexture2DFakeHResult = S_OK;
	int contents = 1964;
	rt::D3D10::SubResourceData data(&contents);
	ID3D10Texture2D *result = m_desc.Create(&device, &data);
	BOOST_REQUIRE(device.CreateTexture2DCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateTexture2DLastDesc);
	BOOST_REQUIRE_EQUAL(&data, device.CreateTexture2DLastData);
	BOOST_REQUIRE_EQUAL(&texture, result);
}

BOOST_AUTO_TEST_SUITE_END()
